package com.augurit.gzcgwsp.qyzz.web;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.orm.Page;
import org.springside.modules.web.struts2.Struts2Utils;

import com.augurit.common.base.action.CrudActionSupport;
import com.augurit.common.util.ExtUtils;
import com.augurit.common.util.lang.DateUtils;
import com.augurit.common.util.lang.StringUtils;
import com.augurit.gzcgwsp.qyzz.entity.YwRqQyzzAzWxRyZs;
import com.augurit.gzcgwsp.qyzz.entity.YwRqRyzzEquipment;
import com.augurit.gzcgwsp.qyzz.service.IYwRqQyzzEquipmentService;

@SuppressWarnings("serial")
@Results({
	@Result(name = "toZmclInfo", location = "/gzcgwsp/qyzz/YwRqQyzzInfo/view/toZmclInfo.jsp"),
	@Result(name = "toEquipmentInfo", location = "/gzcgwsp/qyzz/YwRqQyzzInfo/view/toEquipmentInfo.jsp")
    })
public class YwRqQyzzEquipmentAction extends CrudActionSupport<YwRqRyzzEquipment> {
	@Autowired
	private IYwRqQyzzEquipmentService ywRqQyzzEquipmentService;
	private Page<YwRqRyzzEquipment> page ;

	public Page<YwRqRyzzEquipment> getPage() {
		return page;
	}
	public void setPage(Page<YwRqRyzzEquipment> page) {
		this.page = page;
	}

	/**
	 * 分页统计查询
	 * @return
	 */
    public String toList(){
    	//请求的查询数据
    Map map = getMapByRequest(getRequest());
    
    if(page==null){
  		  page = new Page<YwRqRyzzEquipment>(10);
  	 }
    ExtUtils.initPageFromExtGridParam(getRequest(), page);
  	page=ywRqQyzzEquipmentService.search(page,map);
  	
  	renderText(Struts2Utils.getJsonString(page, DateUtils.YYYY_MM_DD_HH_MM_SS));
  	
  	return null;
  }
    
    
    /**
     * 到设备页面
     * @return
     */
    public String toEquipmentInfo(){
    	String acceptNo=getRequest().getParameter("acceptNo");
    	String qyid=getRequest().getParameter("qyid");
    	getRequest().setAttribute("acceptNo",acceptNo);
    	getRequest().setAttribute("qyid",qyid);
    	return "toEquipmentInfo";
    }
    /**
     * 到证明材料页面
     * @return
     */
    public String toZmclInfo(){
    	String acceptNo=getRequest().getParameter("acceptNo");
    	String qyid=getRequest().getParameter("qyid");
    	getRequest().setAttribute("acceptNo",acceptNo);
    	getRequest().setAttribute("qyid",qyid);
    	return "toZmclInfo";
    }
    
    /**
     * 获取安全人员数据
     * @return
     */
    public String getZmclDatas(){
    	String acceptNo=getRequest().getParameter("acceptNo");
		String qyid=getRequest().getParameter("qyid");
		String type=getRequest().getParameter("type");
	    if(page==null){
	  		  page = new Page(10);
	  	 }
	    ExtUtils.initPageFromExtGridParam(getRequest(), page);
	    
	    if(StringUtils.isNotBlank(acceptNo)){
	    	 page=ywRqQyzzEquipmentService.getPage(acceptNo,page,null,"cl");
	    	 renderText(Struts2Utils.getJsonString(page, DateUtils.YYYY_MM_DD_HH_MM_SS));
	    }
	    if(StringUtils.isNotBlank(qyid)){
	    	 page=ywRqQyzzEquipmentService.getPage("",page,Long.valueOf(qyid),type);
	    	renderText(Struts2Utils.getJsonString(page, DateUtils.YYYY_MM_DD_HH_MM_SS));
	    }
	  
		return null;
    }
    
    /**
     * 获取安全人员数据
     * @return
     */
    public String getDatas(){
    	String acceptNo=getRequest().getParameter("acceptNo");
		String qyid=getRequest().getParameter("qyid");
		String type=getRequest().getParameter("type");
	    if(page==null){
	  		  page = new Page(10);
	  	 }
	    ExtUtils.initPageFromExtGridParam(getRequest(), page);
	    
	    if(StringUtils.isNotBlank(acceptNo)){
	    	 page=ywRqQyzzEquipmentService.getPage(acceptNo,page,null,"");
	    	 renderText(Struts2Utils.getJsonString(page, DateUtils.YYYY_MM_DD_HH_MM_SS));
	    }
	    if(StringUtils.isNotBlank(qyid)){
	    	 page=ywRqQyzzEquipmentService.getPage("",page,Long.valueOf(qyid),type);
	    	renderText(Struts2Utils.getJsonString(page, DateUtils.YYYY_MM_DD_HH_MM_SS));
	    }
	  
		return null;
    }
    
  //获取request对象中所有参数，并设置到map中
	public static Map getMapByRequest(HttpServletRequest request) {
		Map<String, String> map = new HashMap<String, String>();
		Enumeration enu = request.getParameterNames();
		while(enu.hasMoreElements()) {   
            String paraName = (String)enu.nextElement();   
            String paraValue = request.getParameter(paraName).trim(); 
            if(paraValue!=null && !"".equals(paraValue)){
            	map.put(paraName, paraValue);
            }           
		}
				
		return map;
	}
    
	@Override
	public String delete() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String deleteMore() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String list() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	protected void prepareModel() throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Override
	public String save() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}
	public YwRqRyzzEquipment getModel() {
		// TODO Auto-generated method stub
		return null;
	}



   
    
}
